
import numpy as np

# 定义超市名和商品名
stores = ['大润发', '沃尔玛', '好德', '农工商']
products = ['苹果', '香蕉', '橘子', '芒果']

# 创建一个二维数组来存储价格，数组的形状是 (商品数量, 超市数量)
# 使用numpy.random.randint生成4到10之间的随机整数（包含4和10）
prices = np.random.randint(4, 11, size=(len(products), len(stores)))

# 现在，prices数组包含了所有价格信息

print("   " + "   ".join(stores))
for product, row in zip(products, prices):
    print(f"{product:<6}", "   ".join(f"{price:2d}" for price in row))


# 找到大润发和好德在stores中的索引  
idx_drt = stores.index('大润发')  
idx_hd = stores.index('好德')  
  
# 找到苹果和香蕉在products中的索引  
idx_apple = products.index('苹果')  
idx_banana = products.index('香蕉')  
  
# 增加大润发的苹果和好德的香蕉的价格  
prices[idx_apple, idx_drt] += 1  
prices[idx_banana, idx_hd] += 1  
  
# 打印修改后的prices数组  
print("修改后的价格表:")  
print("   " + "   ".join(stores))  
for product, row in zip(products, prices):  
    print(f"{product:<6}", "   ".join(f"{price:2d}" for price in row))


